<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：tudougeaini
 邮箱：877873666@qq.com

 **** 版权所有 **** */



//用户检测
$MB->Open('','login',2);


switch ($mudi){
	case 'add':
		$menuFileID = 303;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'rev':
		$menuFileID = 304;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'del':
		$menuFileID = 305;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		del();
		break;

	case 'loadApiRate':
		$menuFileID = 301;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		LoadApiRate();
		break;

	case 'userInfo':
		$menuFileID = 301;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		UserInfo();
		break;

	default:
		die('err');
}

$MB->Close();
$DB->Close();





// 添加与修改
function AddOrRev(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN;

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$dataID			= OT::PostInt('dataID');

	$theme			= OT::PostStr('theme');
	$url			= OT::PostStr('url');
	$qq				= OT::PostStr('qq');
	$note			= OT::PostStr('note');
	$isApi			= OT::PostInt('isApi');
	$apiID			= OT::PostInt('apiID');
	$apiDomain		= OT::PostStr('apiDomain');
	$apiManageUrl	= OT::PostStr('apiManageUrl');
	if ($apiID == 2){
		$apiUsername	= OT::PostStr('apiUsername2');
		$apiUserPwd		= OT::PostStr('apiUserPwd2');
	}elseif ($apiID == 5){
		$apiUsername	= OT::PostStr('apiUsername5');
		$apiUserPwd		= OT::PostStr('apiUserPwd5');
	}else{
		$apiUsername	= OT::PostStr('apiUsername');
		$apiUserPwd		= OT::PostStr('apiUserPwd');
	}
	$rateDay		= OT::PostFloat('rateDay');
	$rateWeek		= OT::PostFloat('rateWeek');
	$rateMonth		= OT::PostFloat('rateMonth');
	$rate3Month		= OT::PostFloat('rate3Month');
	$rate6Month		= OT::PostFloat('rate6Month');
	$rateYear		= OT::PostFloat('rateYear');
	$rate2Year		= OT::PostFloat('rate2Year');
	$rate3Year		= OT::PostFloat('rate3Year');
	$rate4Year		= OT::PostFloat('rate4Year');
	$rate5Year		= OT::PostFloat('rate5Year');
	$area			= OT::PostArrStr('area','');
	$rank			= OT::PostInt('rank');
	$state			= OT::PostInt('state');

	if ($theme==''){
		JS::AlertBackEnd('表单内容接收不全');
	}

	$record=array();
	$record['VC_theme']			= $theme;
	$record['VC_url']			= $url;
	$record['VC_qq']			= $qq;
	$record['VC_note']			= $note;
	$record['VC_isApi']			= $isApi;
	$record['VC_apiID']			= $apiID;
	$record['VC_apiDomain']		= $apiDomain;
	$record['VC_apiManageUrl']	= $apiManageUrl;
	$record['VC_apiUsername']	= $apiUsername;
	if ($apiUserPwd != '********'){ $record['VC_apiUserPwd'] = Encrypt::SyEnDe('en',$apiUserPwd); }
	$record['VC_rateDay']		= $rateDay;
	$record['VC_rateWeek']		= $rateWeek;
	$record['VC_rateMonth']		= $rateMonth;
	$record['VC_rate3Month']	= $rate3Month;
	$record['VC_rate6Month']	= $rate6Month;
	$record['VC_rateYear']		= $rateYear;
	$record['VC_rate2Year']		= $rate2Year;
	$record['VC_rate3Year']		= $rate3Year;
	$record['VC_rate4Year']		= $rate4Year;
	$record['VC_rate5Year']		= $rate5Year;
	$record['VC_area']			= $area;
	$record['VC_rank']			= $rank;
	$record['VC_state']			= $state;

	$addrec=$DB->query('select * from '. OT_dbPref .'vpsCompany where VC_ID='. $dataID);
		if (! $row = $addrec->fetch()){
			$alertMode='添加';
			$judRes = $DB->InsertParam('vpsCompany',$record);
		}else{
			$alertMode='修改';
			$judRes = $DB->UpdateParam('vpsCompany',$record,'VC_ID='. $dataID);
		}
	unset($addrec);
		if ($judRes){
			$alertRes='成功';
		}else{
			$alertRes='失败';
		}

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】'. $alertMode . $alertRes .'！',
		));

	JS::AlertHref(''. $alertMode .'成功！',$backURL);

}



// 删除
function del(){
	global $DB,$dataType,$dataTypeCN;

	$dataType	= OT::GetStr('dataType');
	$dataTypeCN	= OT::GetStr('dataTypeCN');
	$dataID		= OT::GetInt('dataID');
	$theme		= OT::GetStr('theme');

	if ($dataID<=0){
		JS::AlertEnd('指定ID错误.');
	}

	$useNum = $DB->GetOne('select count(VT_ID) from '. OT_dbPref .'vpsType where VT_companyID='. $dataID);
		if ($useNum > 0){ JS::AlertEnd('该记录已有'. $useNum .'个产品类型占用，请先删除或修改产品类型，再删除！'); }

	$DB->query('delete from '. OT_dbPref .'vpsCompany where VC_ID='. $dataID);

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】删除成功！',
		));

	echo('
	<script language="javascript" type="text/javascript">
	parent.$id("data'. $dataID .'").style.display="none";
	</script>
	');
}



// 读取接口费率
function LoadApiRate(){
	global $DB,$dataType,$dataTypeCN;

	$apiID		= OT::GetInt('apiID');

	$apiexe = $DB->query('select * from '. OT_dbPref .'vpsApi where VA_ID='. $apiID);
	if ($row = $apiexe->fetch()){
		echo('
		$id("rateDayApi").value			= "'. floatval($row['VA_rateDay']) .'";
		$id("rateWeekApi").value		= "'. floatval($row['VA_rateWeek']) .'";
		$id("rateMonthApi").value		= "'. floatval($row['VA_rateMonth']) .'";
		$id("rate3MonthApi").value		= "'. floatval($row['VA_rate3Month']) .'";
		$id("rate6MonthApi").value		= "'. floatval($row['VA_rate6Month']) .'";
		$id("rateYearApi").value		= "'. floatval($row['VA_rateYear']) .'";
		$id("rate2YearApi").value		= "'. floatval($row['VA_rate2Year']) .'";
		$id("rate3YearApi").value		= "'. floatval($row['VA_rate3Year']) .'";
		$id("rate4YearApi").value		= "'. floatval($row['VA_rate4Year']) .'";
		$id("rate5YearApi").value		= "'. floatval($row['VA_rate5Year']) .'";
		try {
			SetRate();
		}catch (e) {}
		');
	}
	unset($apiexe);
}



// 获取账户信息
function UserInfo(){
	global $DB;

	@ini_set('max_execution_time', 0);
	@set_time_limit(0); 

	$dataID	= OT::GetInt('dataID');
		if ( $dataID <= 0 ){ JS::AlertEnd('ID值错误.'); }

	$row = $DB->GetRow('select VC_apiID,VC_apiDomain,VC_apiUsername,VC_apiUserPwd from '. OT_dbPref .'vpsCompany where VC_ID='. $dataID .'');
		if (! $row){ JS::AlertEnd('搜索不到上级渠道商记录['. $dataID .']'); }

	switch ($row['VC_apiID']){
		case 6:		// 网钛IDC
			$rndStr = OT::RndChar(16);
			$dataArr = array(
				'apiDomain'		=> $row['VC_apiDomain'],
				'apiUsername'	=> $row['VC_apiUsername'],
				'apiUserPwd'	=> Encrypt::SyEnDe('de',$row['VC_apiUserPwd']),
				'note'			=> $rndStr,
				);
			$resArr = ApiIdccms::UserInfo($dataArr, 'idcServ');
				if (! $resArr['res']){
					JS::AlertEnd('反馈结果错误。'. $resArr['note']);
				}
			if ($resArr['res']){
				JS::AlertEnd('查询账户信息成功。\n账户：'. $resArr['username'] .'，余额：'. $resArr['userMoney'] .'，折扣：'. $resArr['userRate']*100 .'%.');
			}else{
				JS::AlertEnd('查询账户信息失败。\n反馈内容：'. $resArr['ori'] .'.');
			}
			break;

		default :
			JS::AlertEnd('暂不支持该接口ID（'. $row['VC_apiID'] .'）');
			break;
	}
	unset($companyexe,$typeexe,$proexe,$recexe);

}

?>